package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class MasDict {

	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();

	static {

		STATE.put("00", "Payment accepted");// 成功
		STATE.put("10", "Congratulations ,transaction successful");// 成功
		STATE.put("1000", "Invalid Parameters");
		STATE.put("1001", "Error Occurred While Converting Message");
		STATE.put("1002", "Invalid Request parameters");
		STATE.put("1003", "Error Occurred While verifying Signature");
		STATE.put("1004", "Failed to Verify Signature");
		STATE.put("1005", "Error occurred While Signing");
		STATE.put("1006", "Failed to Sign Message");
		STATE.put("1007", "Parameter Type Not Matches");
		STATE.put("1008", "Invalid Payment Method");
		STATE.put("1009", "The Merchant doesn't have privilege of connect to institute directly");
		STATE.put("1010", "Configure error of direct connection");
		STATE.put("1011", "The institute of direct connection has not been activated");
		STATE.put("1012", "Invalid Parameter Length");
		STATE.put("1015", "Invalid password of the current institute");
		STATE.put("1016", "Charset Not Supported");
		STATE.put("1017", "Charset Can Not Be Empty");
		STATE.put("1017-1", "Language Not Supported");
		STATE.put("1018", "Language Can Not Be Empty");
		STATE.put("1018-1", "Sign Method Not Supported");
		STATE.put("1019", "Sign Method Can Not Be Empty");
		STATE.put("1020", "orgcode is Empty or Not Supported");
		STATE.put("1021", "The orgcode of local payment is not supported");
		STATE.put("1022", "The orgcode of international credit card payment is not supported");
		STATE.put("1023", "Invalid order amount format");
		STATE.put("1024", "Invalid Email Format");
		STATE.put("1025", "Invalid IP address");
		STATE.put("1026", "Invalid Date Format");
		STATE.put("1026-1", "The length of date is larger than 14");
		STATE.put("1027", "Date of the order cannot be empty");
		STATE.put("1028", "Gateway order id cannot be empty");
		STATE.put("1029", "Rate service call exception");
		STATE.put("1030", "Real exchange rate is empty");
		STATE.put("1031", "Session has expired");
		STATE.put("1031-1", "Browser cookie is blocked");
		STATE.put("1032", "Black list filter");
		STATE.put("1032-1 ", "Hit card-number black list");
		STATE.put("1032-2 ", "Hit email black list");
		STATE.put("1032-3 ", "Hit IP black list");
		STATE.put("1032-4 ", "Hit address black list");
		STATE.put("1035", "merchant order number incorrect\uff01");
		STATE.put("2000", "Transaction is abnormal");
		STATE.put("2001", "Unsupported Gateway Version");
		STATE.put("2002", "Duplicate Order Number Detected");
		STATE.put("2002-0", "Duplicate Order Number with Different Payment URL");
		STATE.put("2003", "Merchant Not Exists");
		STATE.put("2004", "Error Occurred  While Notifying the Merchant");
		STATE.put("2005", "Invalid Order Amount");
		STATE.put("2006", "Currency Not Matches");
		STATE.put("2007", "Target institute error");
		STATE.put("2008", "Initiator of the refund must be specified");
		STATE.put("2009", "Acquiring refund order id cannot be empty");
		STATE.put("2010", "Merchant is not available");
		STATE.put("2011", "Refund amount must be specified");
		STATE.put("2012", "Refund id must be specified");
		STATE.put("2013", "Gateway order id must be specified");
		STATE.put("2014", "Currency wallet of the account has not been activated");
		STATE.put("2015", "deposit to this account has been disabled");
		STATE.put("2016", "withdraw from this account has been disabled");
		STATE.put("2017", "This merchant acquiring channel no available");
		STATE.put("2023", "Not enough balance");
		STATE.put("2025", "The order status is error");
		STATE.put("2040", "Refund is not allowed for an order which already has a chargeback");
		STATE.put("2043", "Duplicate refund order number");
		STATE.put("2044", "This institute doesn't support refund");
		STATE.put("2045", "This institution prohibited to do refund");
		STATE.put("2046", "The current transaction is out of the range of refund");
		STATE.put("2047", "The transaction is currently not refundable");
		STATE.put("2100", "Status code error");
		STATE.put("2104", "Connection refused");
		STATE.put("2105", "The request timeout");
		STATE.put("3000", "Payment abnormal");
		STATE.put("3001", "Available refund amount is not enough");
		STATE.put("3002", "The order does not exist.");
		STATE.put("3003", "The order has already been paid");
		STATE.put("3004", "Invalid order amount");
		STATE.put("3005", "withdraw from this account has been disabled");
		STATE.put("3006", "deposit to this account has been disabled");
		STATE.put("3007", "The Original Payment Order Number Does not Exist");
		STATE.put("3008", "Duplicated Payment Request");
		STATE.put("3009", "Acquiring Institute Error");
		STATE.put("3010", "Payment Amount Not Matches");
		STATE.put("3011", "Unknown Payment Status");
		STATE.put("3012", "Information of the payment instruction does not exist");
		STATE.put("3013", "Refund amount is larger than payment amount");
		STATE.put("3014", "Payment at institute side is invalid");
		STATE.put("3015", "The currency is not supported");
		STATE.put("3016", "Payment URL and merchant URL are not matched");
		STATE.put("3017", "Some order number you supplied are not matched");
		STATE.put("3018", "The order has been done");
		STATE.put("3019", "Information of the remittance is not unique");
		STATE.put("3020", "Service type is temporary not support");
		STATE.put("3021", "The remittance's amount you typed is less than the order's amount");
		STATE.put("3022", "Currency of remittance is different from order's");
		STATE.put("3023", "The order is auditing and could not be changed");
		STATE.put("3024", "Institute order does not exist");
		STATE.put("3025", "Institutions do not exist refund orders");
		STATE.put("3026", "Channels resulting state is empty");
		STATE.put("3027", "Exception notification Merchant");
		STATE.put("3028", "Please check the refund amount");
		STATE.put("3029", "Please contact administrator");
		STATE.put("3030", "Do not duplicate payments.");
		STATE.put("3084", "Insufficient funds in the account.");
		STATE.put("3085", "Unable to Verify PIN");
		STATE.put("3086", "Security Policy Violation");
		STATE.put("3088", "Exceed Times Limitation");
		STATE.put("3089", "High risk transaction");
		STATE.put("3091", "Invalid Institute Parameter");
		STATE.put("3092", "Invalid Transaction");
		STATE.put("3093", "Exceed amount limit");
		STATE.put("3094", "Restricted Card");
		STATE.put("3095", "Transaction Timeout");
		STATE.put("3096", "Invalid Expiration");
		STATE.put("3097", "The card type is not accepted by the payment processor");
		STATE.put("3098", "System Busy");
		STATE.put("3099", "System Busy");
		STATE.put("3100", "Do not honor");
		STATE.put("3101", "Invalid Card Information");
		STATE.put("3102", "Expired card");
		STATE.put("3103", "Invalid account");
		STATE.put("3104", "Invalid Card Verification Value (CVV)");
		STATE.put("3105", "The transaction has already been settled or reversed.");
		STATE.put("3106", "Exceeds PIN Retry");
		STATE.put("3107", "You sent within the past 15minutes");
		STATE.put("3108", "It did not pass the Address");
		STATE.put("3109", "You do not receive an authorization code programmatically");
		STATE.put("3110", "Refer to card issuer");
		STATE.put("3111", "Inactive card or card not authorized for card-not-present transactions");
		STATE.put("3117", "The request is missing one or more required fields");
		STATE.put("3118", "Only a partial amount was approved.");
		STATE.put("3119", "Stolen or lost card.");
		STATE.put("3120", "The customer matched an entry on the processor\u2019s negative");
		STATE.put("3121", "The authorization has already been reversed");
		STATE.put("3122", "The authorization has already been captured");
		STATE.put("3123", "stand-alone credits are not allowed");
		STATE.put("3125", "Redirect URL issued");
		STATE.put("3126", "The transaction has been cancelled by the customer");
		STATE.put("3127", "Phone Authorize");
		STATE.put("3128", "Batch Send");
		STATE.put("3129", "Invalid card number");
		STATE.put("3112", "High Risk-Transnational transaction");
		STATE.put("3113", "High Risk-Linked to high risk country");
		STATE.put("3114", "High Risk-Same identity with multiple cards");
		STATE.put("3115", "High Risk-Frequent transactions");
		STATE.put("3116", "High Risk-Other aggregate risk");
		STATE.put("3130", "Institute Transaction Timeout");
		STATE.put("3163", "This card BIN does not allow this transaction");
		STATE.put("4000", "Settled error");
		STATE.put("4001", "Failed to create settlement stream");
		STATE.put("4002", "Institute settlement is failed");
		STATE.put("5000", "Institute is abnormal");
		STATE.put("5001", "Service of the institute is temporarily stopped");
		STATE.put("5002", "Status of the institute is abnormal");
		STATE.put("5003", "Merchant number does not exist in institution");
		STATE.put("5004", "Invalid signature at institute side");
		STATE.put("5005", "Failed to receive notification from institute");
		STATE.put("5006", "Failed to connect to institute");
		STATE.put("5007", "Unknown error from institute");
		STATE.put("5008", "Institute is abnormal");
		STATE.put("5009", "The notification's amount from institute does not match");
		STATE.put("5010", "Unsupported service of the institute");
		STATE.put("5011", "Real paid amount is less than order's");
		STATE.put("5012", "Real refund amount is more than order's");
		STATE.put("6000", "Database error");
		STATE.put("6001", "Database error");
		STATE.put("6002", "Database error");
		STATE.put("7000", "Offline remittance is abnormal");
		STATE.put("7001", "The order is auditing");
		STATE.put("7002", "Real paid currency is different from order's");
		STATE.put("7003", "Real paid amount is less than order's");
		STATE.put("8000", "Gateway order does not exist");
		STATE.put("8001", "Gateway order has already been held on");
		STATE.put("8002", "Gateway order has been wholly refunded");
		STATE.put("8003", "Transaction has been settled");
		STATE.put("8004", "Unfinished transaction");
		STATE.put("8005", "Gateway order has not been held on");
		STATE.put("8006", "Settle data does not exist");
		STATE.put("8007", "PE losses are fail");
		STATE.put("8008", "PE release fails");
		STATE.put("8009", "This channel does not support reconciliation losses are linked");
		STATE.put("9000", "System is maintaining");
		STATE.put("9001", "HTTP request timeout");
		STATE.put("9002", "Unknown exception");
		STATE.put("9003", "MQ is abnormal");
		STATE.put("9004", "MQ Error");
		STATE.put("9005", "System error");
		STATE.put("9006", "Message format is not available");
		STATE.put("9007", "Service is offline");
		STATE.put("CHN9002", "System runtime exception");
		STATE.put("CHN2017", "This merchant acquiring channel no available");

		RISK.put("3099", "3099");

		ALERT.put("555", 0L);
		ALERT.put("2003", 0L);

		// HIDE.put("9905", 0);
	}

	public static synchronized String message(String code) {
		if (STATE.containsKey(code)) {
			return STATE.get(code).toString();
		}
		return "unknown exception";
	}

	public static synchronized void warning(String code, int limit) {
		String name = "MAS";
		String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
		if (ALERT.containsKey(code)) {
			ALERT.put(code, ALERT.get(code) + 1);
			if (new Integer(ALERT.get(code).toString()) > limit) {
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time + "]" + name + "返回码[" + code + "]超过[" + limit + "]次");
			}
		}
	}

}
